{extend name="../../admin/view/main"}

{block name="content"}
<form id="FieldsSortForm" action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="MenuTable">
	<table class="layui-table">
		<colgroup>
			<col width="80">
			<col width="30%">
			<col width="30%">
			<col>
		</colgroup>
		<thead>
			<tr>
				<th class="text-center">排序</th>
				<th class="text-center">字段</th>
				<th class="text-center">描述</th>
				<th class="text-center">操作</th>
			</tr> 
		</thead>
		<tbody>
			{foreach $fields as $vo}
			<tr {if $vo.ordinal_position gt 1} data-field-item {/if}>
				<td align="center"><input type="hidden" name="ordinal_position[]" value="{$vo.ordinal_position}">{$vo.ordinal_position}</td>
				<td align="center">{$vo.column_name|default=""}</td>
				<td align="center">{$vo.column_comment|default=""}</td>
				<td align="center">
					{if $vo.ordinal_position gt 1}
					<a data-item-up class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-up"></i></a>
					<a data-item-dn class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon layui-icon-down"></i></a>
					{/if}
				</td>
			</tr>
			{/foreach}
		</tbody>
	</table>
	<div class="hr-line-dashed"></div>
	{notempty name='vo.table_name'}<input type='hidden' value='{$vo.table_name}' name='table_name'>{/notempty}
	<div class="layui-form-item text-center">
		<button class="layui-btn" type='submit'>{:lang('保存数据')}</button>
		<button class="layui-btn layui-btn-danger" type='button' data-confirm="{:lang('确定要取消吗？')}" data-close>{:lang('取消')}</button>
	</div>
</form>
<script>
    $(function () {
        /*! 表单元素操作 */
        $('form#FieldsSortForm').on('click', '[data-item-up]', function () {
            var item = $(this).parents('[data-field-item]');
            var prev = item.prev('[data-field-item]');
            if (item.index() > 0) item.insertBefore(prev);
        }).on('click', '[data-item-dn]', function () {
            var item = $(this).parents('[data-field-item]');
            var next = item.next('[data-field-item]');
            if (next) item.insertAfter(next);
        });
    });
</script>
{/block}